package com.dyxy.tms.module;

import com.dyxy.tms.UserInfo;
import com.dyxy.tms.base.BaseActivity;
import com.dyxy.tms.module.i1terface.IUserLoginView;
import com.dyxy.tms.utils.NetWorkUtils;

import java.util.jar.Attributes.Name;

import com.dyxy.tms.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends BaseActivity implements IUserLoginView {
	private EditText uname, upwd;
	private String username, userpwd;
	private long exitTime = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_login);
		init();
	}

	private void init() {
		uname = (EditText) findViewById(R.id.layout_login_edname);
		upwd = (EditText) findViewById(R.id.layout_login_edpwd);

	}

	public void Login(View v) {
		if (new NetWorkUtils().isNetworkAvailable(getApplicationContext())) {
			Intent intent = new Intent(LoginActivity.this, MainActivity.class);
			startActivity(intent);
		}else {
			Toast.makeText(getApplicationContext(), "请检查您的网络连接！", Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	public String getUserName() {
		// TODO Auto-generated method stub
		username = uname.getText().toString();
		return null;
	}

	@Override
	public String getPassword() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void clearUserName() {
		// TODO Auto-generated method stub

	}

	@Override
	public void clearPassword() {
		// TODO Auto-generated method stub

	}

	@Override
	public void showLoading() {
		// TODO Auto-generated method stub

	}

	@Override
	public void hideLoading() {
		// TODO Auto-generated method stub

	}

	@Override
	public void toMainActivity(UserInfo userinfo) {
		// TODO Auto-generated method stub

	}

	@Override
	public void showFailedError() {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			exit();
			return false;
		}
		return super.onKeyDown(keyCode, event);
	}

	public void exit() {
		if ((System.currentTimeMillis() - exitTime) > 2000) {
			Toast.makeText(getApplicationContext(), "再按一次退出程序", Toast.LENGTH_SHORT).show();
			exitTime = System.currentTimeMillis();
		} else {
			finish();
			System.exit(0);
		}
	}

}
